#!/usr/bin/env python3

import logging
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
from multiprocessing import Process,Queue
from scapy.all import *
from b1_arp_one import arp_one
import time
def arp_segment(ip_segment):
	ip_segment = ipaddress.ip_network(ip_segment)#ipaddress.ip_network可以将字段和掩码自动分出有多少IP
	arp_queue = Queue()#创建一个队列
	for ip_addr in ip_segment:
		ip_addr = str(ip_addr)
		arp_one_result = Process(target=arp_one,args=(ip_addr,arp_queue))
		arp_one_result.start()
	time.sleep(2)
	ip_mac_dict = {}
	while True:
		if arp_queue.empty():#如果队列为空则退出循环
			break
		else:
			ip,mac = arp_queue.get()#如果不为空，则不断提取队列传输过来的IP MAC映射，也可以用ip,mac接收
			#print(ip_mac)
			ip_mac_dict[ip] = mac
	return ip_mac_dict

if __name__ == "__main__":
	import sys
	segment = input("输入要扫描的网段：")
	ip_mac_dict = arp_segment(segment)

	for x,y in ip_mac_dict.items():
		print(x + "-->" + y)
